package com.pignest.hotel.ui.listener;

import javax.servlet.http.HttpServletRequest;

import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.EventThreadInit;

import com.pignest.framework.util.Log;
import com.pignest.hotel.beans.global.ClientSession;
import com.pignest.hotel.system.AuthenticatorHolder;
import com.pignest.hotel.system.Key;

public class ThreadInitListener implements EventThreadInit {

	@Override
	public boolean init(Component comp, Event event) throws Exception {
		Log.d(comp.getClass().getSimpleName() + "\t" + Thread.currentThread().getName());
		try {
			HttpServletRequest request = (HttpServletRequest)comp.getDesktop().getExecution().getNativeRequest();
			ClientSession cs = (ClientSession)request.getSession().getAttribute(Key.CLIENT_SESSION);
			AuthenticatorHolder.setClientSession(cs);
		} catch (Exception e) {
			Log.e(e);
		}
		return true;
	}

	@Override
	public void prepare(Component comp, Event event) throws Exception {
	}

}
